import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/page/clouds/clouds_page.dart';
import 'package:full_display/page/help/help_page.dart';
import 'package:full_display/page/login/login_page.dart';
import 'package:full_display/page/medium/medium_page.dart';
import 'package:full_display/page/montage/montage_page.dart';
import 'package:full_display/page/single/single_page.dart';
import 'package:full_display/unit/widgets/widget_tabbar/tabbar_item.dart';

import 'generated/l10n.dart';

class IndexPage extends StatefulWidget {
  const IndexPage({super.key});

  @override
  State<IndexPage> createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final List<Widget> tabarList = [
    // const SinglePage(),
    const MontageWidget(),
    const CloudsPage(),
    const MediumPage(),
    const HelpWidget(),
    const LoginWidget(),
  ];

  int _currentIndex = 0;
  var _currentPage;

  @override
  void initState() {
    _currentPage = tabarList[_currentIndex];
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.light,
    ));
    return
        // const Scaffold(
        //   body: SinglePage(),
        // );
        Scaffold(
      body: IndexedStack(
        index: _currentIndex,
        children: tabarList,
      ),
      backgroundColor: ColorPlate.background,
      // appBar: AppBar(
      //   backgroundColor: Colors.transparent,
      //   elevation: 0,
      // ),
      extendBodyBehindAppBar: true,
      bottomNavigationBar: BottomNavigationBar(
        items: [
          _initTabItem('alone', 'alone_select', S.of(context).danji),
          _initTabItem(
              'splicing', 'splicing_select', S.of(context).Joining_together),
          _initTabItem('network', 'network_select', S.of(context).yunduan),
          _initTabItem('media', 'media_select', S.of(context).meitiku),
          _initTabItem('help', 'help_select', S.of(context).bangzhu),
        ],
        backgroundColor: ColorPlate.background,
        unselectedItemColor: ColorPlate.tabbar_noselect,
        selectedItemColor: ColorPlate.app_blue,
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (index) => {
          setState(() {
            if (_currentIndex != index) {
              _currentIndex = index;
              // _currentPage = tabarList[_currentIndex];
            }
          })
        },
      ),
    );
  }

  // 初始化baritem
  BottomNavigationBarItem _initTabItem(
          String iconName, String activeIconName, String title) =>
      BottomNavigationBarItem(
          icon: buildImage(iconName),
          activeIcon: buildImage(activeIconName),
          label: title);
}
